v=input()

if len(v)!=4:
    print(0)
    exit()


v0,v1,v2,v3=v[0],v[1],v[2],v[3]
v01,v12,v23=v[0]+v[1],v[1]+v[2],v[2]+v[3]
v012,v123=v[0]+v[1]+v[2],v[1]+v[2]+v[3]

spn=[v0,v1,v2,v3,v01,v12,v23,v012,v123]
pr=[]


for i in spn:
    i=int(i)
    prost=True
    for j in range(2,i):
        if i%j==0:
            prost=False
    if prost:
        pr.append(i)

if len(pr)==0:
    print(0)
    exit()


print(max(pr))
